package {
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.media.*;
	public class IsoContainer extends Sprite {
		private var layers: Array = [];
		public function IsoContainer() {
			for (var i: int = 0; i < 30; i++) {
				var layer: Sprite = new Sprite();
				addChild(layer);
				layers.push(layer);
			}
		}
		
		public function addIsoSprite(sprite: IsoSprite): void {
			var z: int = sprite.iz;
			var layer: Sprite = layers[z + 5];
			sprite.isoParent = this;
			
			var i: int;
			for (i = 0; i < layer.numChildren; i++) {
				if (IsoSprite(layer.getChildAt(i)).depth > sprite.depth) {
					break;
				}
			}
			layer.addChildAt(sprite, i);
		}
		
		public function removeIsoSprite(sprite: IsoSprite): void {
			sprite.parent.removeChild(sprite);
			sprite.isoParent = null;
		}
		
		public function resort(sprite: IsoSprite): void {
			removeIsoSprite(sprite);
			addIsoSprite(sprite);
		}
	}
}